package com.aop.SpElAop.DistributedLock.RedisLock.Test;

import com.aop.SpElAop.DistributedLock.RedisLock.RedisLock;
import com.aop.SpElAop.DistributedLock.RedisLock.Test.LockDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.concurrent.TimeUnit;

/**
 * @Package: com.aop.SpElAop.DistributedLock.Lock.RedisLock.Test
 * @ClassName: TestLockService
 * @Author: h2cloud
 * @CreateTime: 2024/7/9 11:13 下午
 * @Description:
 */
@Service
public class TestLockService {

	@Autowired
	private TestLockService testLockService;

	@RedisLock(name = "demo", key = "#param.id")
	public String single(@RequestBody LockDTO param) {
		try {
			testLockService.single2(param);
			TimeUnit.SECONDS.sleep(60);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "OK";
	}

	@RedisLock(name = "demo", key = "#param.id")
	public String single2(@RequestBody LockDTO param) {
		try {
			TimeUnit.SECONDS.sleep(60);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "OK";
	}
}
